package com.wn.controller;

import com.wn.entity.Student;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RequestMapping("/user")
@RestController
public class JsonTestCon {
    @RequestMapping( value="/findOne",produces = "application/json;charset=UTF-8")
    public Student findOne(@RequestBody Student student){
        System.out.println("JsonTestController.findOne:"+student);
        return student;
    }

    /**
     * 传输字符串 通过json
     * @param student 字符串
     * @return student字符串
     */
    @RequestMapping( value="/updateOne",produces = "application/json;charset=UTF-8")
    public String findOne(@RequestBody String student){
        System.out.println("JsonTestController.findOne:"+student);
        return student;
    }

    /**
     * 前端json如下：   [1,3,4]
     * @param array 可以是数组对象可以是集合对象
     * @return
     */
    @RequestMapping(value = "/findArray")
    public int[] findArray(@RequestBody int[] array){
        for (int i : array) {
            System.out.println("JsonTestController.findArray:"+i);
        }
        return array;
    }

    /**
     *  Map能够接受任意类型的json对象
     * @param map
     * @return
     */
    @RequestMapping(value = "/findMap")
    public Map<String,Object> findMap(@RequestBody Map<String,Object> map){
        Student student = new Student();
        return map;
    }

    /**
     * 处理List中是Map结构的json对象
     * @param listMap
     * @return
     */
    @RequestMapping(value = "/findListMap")
    public List<Map<String,Object>> findListMap(@RequestBody List<Map<String,Object>> listMap){
        return listMap;
    }

    /**
     * 处理复杂对象 内部含list、Map等json对象
     * @param clazzRoom
     * @return
     */
   /* @RequestMapping(value = "/findClazzRoom")
    public ClazzRoom findClazzRoom(@RequestBody ClazzRoom clazzRoom){
        return clazzRoom;
    }*/
}
